rvConfig = function () {

	var VIEWER_SERVER_PRODUCITON = "http://rvashow.appspot.com";
	var VIEWER_SERVER_TEST = "http://viewer-test.appspot.com"; 
	var VIEWER_PATH = "/Viewer.html?player=true&type=display&id=";

	this.displayId = "";
	this.claimId = "";
	this.screenWidth = 0;
	this.screenHeight = 0;
	
	this.server = "production";
	this.viewerServer = VIEWER_SERVER_PRODUCITON;
	
	this.init = function(onLoadCallback) {
		this.loadDisplayProperties(onLoadCallback);
	};
	
	this.getViewerUrl = function() {
		if (this.server == "test") {
			this.viewerServer = VIEWER_SERVER_TEST;
		} else {
			this.viewerServer = VIEWER_SERVER_PRODUCITON;
		}
		return this.viewerServer + VIEWER_PATH + this.displayId
	};

	this.saveDisplayProperties = function(callback) {
		// use Chrome extension storage API.
		
		chrome.storage.local.set({
			'displayId' : this.displayId,
			'claimId' : this.claimId,
			'server' : this.server
		}, function() {
			if (chrome.runtime.lastError) {
			    console.error('saveDisplayProperties error ' + chrome.runtime.lastError);
			}
			if (callback) {
				callback();
			}
		});
	};
	
	this.clearStorage = function() {
		this.displayId = "";
		this.claimId = "";
		this.server = "production";
		chrome.storage.local.clear(function() {
			if (chrome.runtime.lastError) {
			    console.error('saveDisplayProperties error ' + chrome.runtime.lastError);
			}
		});
	};

	this.saveScreenSize = function(w,h) {
		this.screenWidth = w;
		this.screenHeight = h;
		chrome.storage.local.set({
			'screenWidth' : this.screenWidth,
			'screenHeight' : this.screenHeight
		}, function() {
			if (chrome.runtime.lastError) {
			    console.error('saveScreenSize error ' + chrome.runtime.lastError);
			}
		});
	};

	this.loadDisplayProperties = function(onLoadCallback) {
		var self = this;
		chrome.storage.local.get(['displayId','claimId','server','screenWidth','screenHeight'], function(items) {
			if (chrome.runtime.lastError) {
			    console.error('loadDisplayProperties error ' + chrome.runtime.lastError);
			} else {
				self.displayId = items.displayId ? items.displayId : "";
				self.claimId = items.claimId ? items.claimId : "";
				self.server = items.server ? items.server : "production";
				self.screenWidth = items.screenWidth ? items.screenWidth : 600;
				self.screenHeight = items.screenHeight ? items.screenHeight : 400;
				console.log('Display ID: ' + self.displayId + ' | Claim ID: ' + self.claimId  + ' | Server: ' + self.server);
				console.log('screenWidth: ' + self.screenWidth + ' | screenHeight: ' + self.screenHeight);
			}
			if (onLoadCallback) {
				onLoadCallback(chrome.runtime.lastError);
			}
		});
	};

};

